package com.tasly.attendance.domain.calc.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.tasly.attendance.domain.calc.Calculator;

/**
 * Use this calculator to anaylse the resting hours
 * only have the records before 10:00
 * 
 * @author Sam Li
 *
 */
public class RestingWorkingHoursCalculatorImpl implements Calculator {
    
    private static final double RESTING_WORKING_HOURS = 0;

    @Override
    public double calculate(List<Date> dateCalculatePoolList,Date dateLimit) {
        
        Calendar calendar = Calendar.getInstance();
        Date standardDatetime = null;
//        Date standardEndDateTime = null;
        //8 hours check
        calendar.setTime(dateLimit);
        //set start time to 10:00
        calendar.set(Calendar.HOUR_OF_DAY, 10);
        standardDatetime = calendar.getTime();
        //set end time to 17:30
//        calendar.set(Calendar.HOUR_OF_DAY, 20);
//        calendar.set(Calendar.MINUTE, 30);
//        standardEndDateTime = calendar.getTime();
        //get first swing card time in the day
        Date firstSwingCardDateTime = dateCalculatePoolList.get(0);
        //get latest swing card time in the day
        Date latestSwingCardDateTime = dateCalculatePoolList.get(dateCalculatePoolList.size()-1);
        if (firstSwingCardDateTime.before(standardDatetime)
                && latestSwingCardDateTime.before(standardDatetime)) {
            return RESTING_WORKING_HOURS;
        } else {
            return INVALID_HOURS;
        }
    }

}
